<?php
/**
 * Created by PhpStorm.
 * User: DaibiDaddy
 * Date: 2016/6/3
 * Time: 14:59
 */

namespace Model\QuestionBundle\Setting;

use Model\QuestionCategoryBundle\Model\QuestionCategoryModel;

class QuestionSetting{

    /*手动获取的配置项*/
    public $entityCnName = "题目";//模块名称
    public $table = "Question";//数据表名称
    public $editKeys = array();//后台管理列表中可以直接编辑的字段
    public $perPage = 10;//后台管理列表中可以直接编辑的字段

    /*自动获取的配置项*/
    public $bundleName;
    public $entityName;
    public $SettingPath;
    public $entityPath;
    public $entity;
    public $modelPath;
    public $em;

    public function __construct($em)
    {
        $this->bundleName = str_replace("\\","",str_replace("Setting","",__NAMESPACE__));
        $this->entityName = str_replace("\\","",str_replace("Setting","",str_replace(__NAMESPACE__,"",__CLASS__)));
        $this->SettingPath = __CLASS__;
        $this->entityPath = str_replace($this->entityName."Entity",$this->entityName,str_replace("Setting","Entity",__CLASS__));
        $this->entity = new $this->entityPath();
        $this->modelPath = str_replace("Setting","Model",__CLASS__);
        $this->em = $em;
    }

    public function listConfig()
    {
        $default = array();
        $default["Question"]["select"] = array("id","title","difficulty");
        $default["Question"]["search"] = array("title");
        $default["Question"]["condition"] = array("sort");
        $default["Question"]["orderBy"] = array();

        $join = array();
        $join["CourseCategory"]["on"] = "CourseCategory.id = Question.sort";
        $join["CourseCategory"]["select"] = array("name");
        $join["CourseCategory"]["search"] = array();
        $join["CourseCategory"]["condition"] = array();
        $join["CourseCategory"]["orderBy"] = array();

        return array(
            "default"   => $default,
            "joins"     => $join,
        );
    }

    public function formConfig()
    {
        $type["other"] = array(
            "choices"   => array("0"=>"单选题","1"=>"多选题"),
        );
        $config["type"] = array(
            "label"     =>"选项类型",
            "showType"  =>"select",
            "dataType"  =>"",
            "option"    => $type
        );
        $config["title"] = array(
            "label"     =>"题干",
            "showType"  =>"text",
            "dataType"  =>"",
            "option"    => array()
        );
        $config["difficulty"] = array(
            "label"     =>"难度系数",
            "showType"  =>"text",
            "dataType"  =>"",
            "option"    => array()
        );
        $config["answerAnalyze"] = array(
            "label"     =>"答案解析",
            "showType"  =>"article",
            "dataType"  =>"",
            "option"    => array()
        );
        return $config;
    }
}